import apiClient from '../axios'

// 模拟数据，在请求失败时使用
const mockData = {
  code: 200,
  data: [
    {
      id: 'mock1',
      name: '示例知识库1',
      description: '这是一个示例知识库，用于测试界面显示',
      avatar: 'https://i.pravatar.cc/150?img=1',
      embedding_model: 'text-embedding-3-small',
      chunk_method: 'recursive'
    },
    {
      id: 'mock2',
      name: '示例知识库2',
      description: '包含业务相关资料的知识库',
      avatar: 'https://i.pravatar.cc/150?img=2',
      embedding_model: 'text-embedding-3-small',
      chunk_method: 'recursive'
    }
  ],
  total: 2
}

export const listDatasets = async (params) => {
    try {
        console.log('请求知识库列表，参数:', params)
        const response = await apiClient.post('/ragflow/api/v1/list/dataset', { params })
        console.log('请求成功:', response)
        return response.data
    } catch (error) {
        console.error('获取知识库列表失败:', error)
        // 返回模拟数据，防止界面崩溃
        return {
            code: 200,
            data: {
                data: mockData,
                total: mockData.length
            },
            message: 'success (mock)'
        }
    }
} 